if (!("finalizeConstruction" in ViewPU.prototype)) {
    Reflect.set(ViewPU.prototype, "finalizeConstruction", () => { });
}
import Config from '../constants/Config';
import { TimeMode } from '../constants/TimeMode';
import window from '@ohos.window';
let context = getContext(this);
export class TimeNavView extends ViewPU {
    constructor(c13, d13, e13, f13 = -1, g13 = undefined, h13) {
        super(c13, e13, f13, h13);
        if (typeof g13 === "function") {
            this.paramsGenerator_ = g13;
        }
        this.__curTimeStamp = this.initializeConsume("curTimeStamp", "curTimeStamp");
        this.timeMode = 0;
        this.selectedDate = new Date();
        this.onTimeChange = undefined;
        this.uiContext = undefined;
        this.startTime = '';
        this.endTime = '';
        this.setInitiallyProvidedValue(d13);
        this.finalizeConstruction();
    }
    setInitiallyProvidedValue(b13) {
        if (b13.timeMode !== undefined) {
            this.timeMode = b13.timeMode;
        }
        if (b13.selectedDate !== undefined) {
            this.selectedDate = b13.selectedDate;
        }
        if (b13.onTimeChange !== undefined) {
            this.onTimeChange = b13.onTimeChange;
        }
        if (b13.uiContext !== undefined) {
            this.uiContext = b13.uiContext;
        }
        if (b13.startTime !== undefined) {
            this.startTime = b13.startTime;
        }
        if (b13.endTime !== undefined) {
            this.endTime = b13.endTime;
        }
    }
    updateStateVars(a13) {
    }
    purgeVariableDependenciesOnElmtId(z12) {
        this.__curTimeStamp.purgeDependencyOnElmtId(z12);
    }
    aboutToBeDeleted() {
        this.__curTimeStamp.aboutToBeDeleted();
        SubscriberManager.Get().delete(this.id__());
        this.aboutToBeDeletedInternal();
    }
    get curTimeStamp() {
        return this.__curTimeStamp.get();
    }
    set curTimeStamp(y12) {
        this.__curTimeStamp.set(y12);
    }
    aboutToAppear() {
        window.getLastWindow(context)
            .then((x12) => {
            this.uiContext = x12.getUIContext();
        })
            .catch((w12) => {
        });
    }
    initialRender() {
        this.observeComponentCreation2((r12, s12) => {
            RelativeContainer.create();
            RelativeContainer.width(Config.FULL_PERCENT);
            RelativeContainer.height(24);
            RelativeContainer.margin({ top: 12 });
            RelativeContainer.onAppear(() => this.onTimeChange && this.onTimeChange(this.curTimeStamp, this.startTime, this.endTime));
        }, RelativeContainer);
        this.observeComponentCreation2((p12, q12) => {
            RelativeContainer.create();
            RelativeContainer.id("rel_1");
            RelativeContainer.width(12);
            RelativeContainer.height(24);
            RelativeContainer.margin({ left: 15 });
            RelativeContainer.alignRules({
                center: { anchor: "__container__", align: VerticalAlign.Center },
                left: { anchor: "__container__", align: HorizontalAlign.Start }
            });
        }, RelativeContainer);
        this.observeComponentCreation2((m12, n12) => {
            Image.create({ "id": -1, "type": 20000, params: ["app.media.ic_arrow_left"], "bundleName": "__harDefaultBundleName__", "moduleName": "__harDefaultModuleName__" });
            Image.id("image_left");
            Image.width(7);
            Image.height(14);
            Image.onClick(() => {
                this.changeTime(-1);
            });
            Image.alignRules({
                center: { anchor: "__container__", align: VerticalAlign.Center },
                middle: { anchor: "__container__", align: HorizontalAlign.Center }
            });
        }, Image);
        RelativeContainer.pop();
        this.observeComponentCreation2((i12, j12) => {
            Text.create(this.getTimeStr());
            Text.fontSize(15);
            Text.fontColor("#999999");
            Text.onClick(() => {
                this.uiContext?.showDatePickerDialog({
                    start: new Date("2000-1-1"),
                    end: new Date("2100-12-31"),
                    selected: new Date(this.curTimeStamp),
                    onAccept: (l12) => {
                        this.curTimeStamp = new Date(Number(l12.year), Number(l12.month), Number(l12.day)).getTime();
                        this.getTimeStr();
                        this.onTimeChange && this.onTimeChange(this.curTimeStamp, this.startTime, this.endTime);
                        console.info("DatePickerDialog:onAccept()" + JSON.stringify(l12));
                    },
                });
            });
            Text.alignRules({
                center: { anchor: "__container__", align: VerticalAlign.Center },
                middle: { anchor: "__container__", align: HorizontalAlign.Center }
            });
            Text.id("text");
        }, Text);
        Text.pop();
        this.observeComponentCreation2((f12, g12) => {
            Image.create({ "id": -1, "type": 20000, params: ["app.media.ic_down"], "bundleName": "__harDefaultBundleName__", "moduleName": "__harDefaultModuleName__" });
            Image.width(12);
            Image.aspectRatio(1.4);
            Image.id("image_arrow");
            Image.alignRules({
                center: { anchor: "__container__", align: VerticalAlign.Center },
                left: { anchor: "text", align: HorizontalAlign.End }
            });
            Image.onClick(() => {
                this.changeTime(-1);
            });
            Image.margin({ left: 9 });
        }, Image);
        this.observeComponentCreation2((d12, e12) => {
            RelativeContainer.create();
            RelativeContainer.id("rel_2");
            RelativeContainer.width(12);
            RelativeContainer.height(24);
            RelativeContainer.margin({ right: 15 });
            RelativeContainer.alignRules({
                center: { anchor: "__container__", align: VerticalAlign.Center },
                right: { anchor: "__container__", align: HorizontalAlign.End }
            });
        }, RelativeContainer);
        this.observeComponentCreation2((a12, b12) => {
            Image.create({ "id": -1, "type": 20000, params: ["app.media.ic_arrow_right"], "bundleName": "__harDefaultBundleName__", "moduleName": "__harDefaultModuleName__" });
            Image.width(7);
            Image.height(14);
            Image.id("image_right");
            Image.alignRules({
                center: { anchor: "__container__", align: VerticalAlign.Center },
                middle: { anchor: "__container__", align: HorizontalAlign.End }
            });
            Image.margin({ right: 16 });
            Image.onClick(() => {
                this.changeTime(1);
            });
        }, Image);
        RelativeContainer.pop();
        RelativeContainer.pop();
    }
    changeTime(s11) {
        switch (this.timeMode) {
            case TimeMode.Day:
                this.getDayBounds(24 * 60 * 60 * 1000 * s11);
                break;
            case TimeMode.Week:
                this.getWeekBounds(7 * 24 * 60 * 60 * 1000 * s11);
                break;
            default:
                break;
        }
        if (this.onTimeChange) {
            this.onTimeChange(this.curTimeStamp, this.startTime, this.endTime);
        }
    }
    getTimeStr() {
        switch (this.timeMode) {
            case TimeMode.Day:
                return this.getDayBounds(0);
            case TimeMode.Week:
                return this.getWeekBounds(0);
            default:
                return "";
        }
    }
    fillZero(r11) {
        return r11 < 10 ? '0' + r11 : r11;
    }
    getDayBounds(k11) {
        this.curTimeStamp = this.curTimeStamp + k11;
        let l11 = new Date(this.curTimeStamp);
        const m11 = l11.getFullYear();
        const n11 = l11.getMonth() + 1;
        const o11 = l11.getDate();
        const p11 = ['日', '一', '二', '三', '四', '五', '六'];
        const q11 = p11[l11.getDay()];
        this.startTime = `${m11}-${this.fillZero(n11)}-${this.fillZero(o11)}`;
        this.endTime = `${m11}-${this.fillZero(n11)}-${this.fillZero(o11)}`;
        return `${m11}年${n11}月${o11}日`;
    }
    getWeekBounds(x10) {
        this.curTimeStamp = this.curTimeStamp + x10;
        let y10 = new Date(this.curTimeStamp);
        const z10 = (y10.getDay() + 6) % 7;
        const a11 = new Date(y10.getFullYear(), y10.getMonth(), y10.getDate() - z10);
        const b11 = new Date(a11.getFullYear(), a11.getMonth(), a11.getDate() + 6);
        const c11 = a11.getFullYear();
        const d11 = a11.getMonth() + 1;
        const e11 = a11.getDate();
        const f11 = b11.getFullYear();
        const g11 = b11.getMonth() + 1;
        const h11 = b11.getDate();
        const i11 = `${c11}年${d11}月${e11}日`;
        const j11 = `${f11}年${g11}月${h11}日`;
        this.startTime = `${c11}-${this.fillZero(d11)}-${this.fillZero(e11)}`;
        this.endTime = `${f11}-${this.fillZero(g11)}-${this.fillZero(h11)}`;
        return i11 + "-" + j11;
    }
    rerender() {
        this.updateDirtyElements();
    }
}
